how to sum based on multiple conditions

join shbcf.ru